import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { Reducers } from "../../../../../App";
import { formShow_editAct } from "../../store/actions";
import { IReducerState_Form } from "../../store/reducer";
import { IColumn } from "../../interfaces";

interface IPropsState {
  form: IReducerState_Form;
}

interface IPropsDispatch {
  show: (id: number, form: IReducerState_Form) => void;
}

interface IExtra {
  record: IColumn;
}

type TProps = IPropsState & IPropsDispatch & IExtra;

const Action: React.FC<TProps> = props => {
  const { show, form, record } = props;

  function onClick() {
    show(record.id, form);
  }

  return (
    <span className="action" onClick={() => onClick()}>
      修改
    </span>
  );
};

function mapStateToProps(state: Reducers): IPropsState {
  const reducer = state.manageOrderReducer;
  return {
    form: reducer.form_info
  };
}

const mapDispatchToProps = (dispatch: Dispatch): IPropsDispatch => ({
  show(id: number, form: IReducerState_Form) {
    const action: any = formShow_editAct(id, form);
    dispatch(action);
  }
});

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Action);
